<template>
  <div class="loginContainer">
    <div class="topContainer">
      <!-- 跳到首页 -->
      <a href="/" class="home">
        <van-icon name="wap-home-o" size="34" color="#333" />
      </a>
      <a href="/" class="logo">网易严选</a>
      <!-- 跳转到搜索页 -->
      <a href="/search" class="search">
        <van-icon name="search" size="34" color="#333" />
      </a>
      <!-- 跳转到购物车 -->
      <a href="/shopCar" class="shopCar">
        <van-icon name="shopping-cart-o" size="34" color="#333" />
      </a>
    </div>
    <div class="centerContainer">
      <div class="wytext">
        <img src="../../../assets/logo.png" alt="" />
      </div>
      <div class="inputStyle">
        <van-form @failed="onFailed">
          <van-cell-group inset>
            <van-field
              label-class="inputType"
              clearable
              v-model="phone"
              placeholder="请输入手机号"
              size="large"
              center
              name="pattern"
              :rules="[{ pattern, message: '手机格式不正确' }]"
            />
          </van-cell-group>
        </van-form>
        <van-cell-group inset>
          <van-field
            center
            clearable
            label-class="inputType"
            placeholder="请输入短信验证码"
            v-model="code"
          >
            <template #button>
              <van-button size="mini" type="default" @click="sendCode"
                >发送验证码</van-button
              >
            </template>
          </van-field>
        </van-cell-group>
        <div class="help">
          <span>遇到问题？</span>
          <span class="password">使用密码验证登录</span>
        </div>
        <van-button type="danger" size="large" class="login">登录</van-button>
        <div class="about">
          <input type="checkbox" />
          <span
            >同意<a href="#javascript">《服务条款》</a>和<a href="#javascript"
              >《隐私政策》</a
            >和<a href="#javascript">《网易严选服务协议》</a></span
          >
        </div>
      </div>
      <div class="choose">选择其他登录方式<span>></span></div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import {reqCode} from '@/api/lgoin'
const checked = ref(false);
const groupChecked = ref([]);
// 手机号校验
const phone = ref("");
const pattern = /^1[3-9][0-9]{9}$/;
// 定义验证码
const code = ref('')
// 发送验证码
const sendCode = async () => {
  console.log('test',phone.value);
  
  if (!phone.value) {
      alert('请输入手机号')
      return
    }
  try {
    // 发送请求
    let res = await reqCode(phone.value)
    console.log(res);
    code.value = res.data
    
  } catch (error) {
    return Promise.reject(error)
  }
}
</script>

<style scoped lang="less">
* {
  margin: 0;
  padding: 0;
}
.loginContainer {
  height: 100%;
}
.topContainer {
  width: 100%;
  height: 47px;
  background-color: #fafafa;
  line-height: 47px;
  .topCenter {
    width: 400px;
    height: 47px;
    line-height: 55px;
  }
  .home {
    margin-left: 10px;
  }
  .logo {
    font-size: 20px;
    color: #333;
    margin-left: 100px;
    margin-right: 55px;
    font-weight: 700;
  }
  .search {
    margin-right: 25px;
  }
}
.centerContainer {
  background: #f2f5f4;
  height: 100%;
  .wytext {
    text-align: center;
    padding-top: 1.6rem;
    img {
      width: 3.6rem;
      height: 1.3rem;
    }
  }
  .inputStyle {
    margin: 0 0.6rem;
    .inputType {
      font-size: 0.5rem;
      width: 8.27rem;
      height: 0.6rem;
      font-size: 0.4rem;
      line-height: 0.6rem;
      margin: 0.39rem 0;
      padding-left: 0;
    }
  }
  .help {
    font-size: 0.4rem;
    margin-top: 0.2rem;
    .password {
      float: right;
    }
  }
  .login {
    margin: 0.5rem 0;
  }
  .about {
    display: flex;
    font-size: 0.18rem;
    span {
      margin-left: 0.09rem;
      a {
        color: blue;
      }
    }
  }
  .choose {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.35rem;
  }
}
</style>
